<?php
namespace Common\Controller;
use Think\Controller;
class BaseController extends Controller{
    public function __construct() {
       parent::__construct();
       if (!session('?name')) {
           $this->error('没有登录', U('Login/login'));
       }
           $this->checkLogin();

       $this->showMenus();
   }

    protected function getDict($field){
        $where=[
            'field'=>$field,
            'lock'=>0
        ];
        $res=M('dict')->where($where)->select();
        $this->assign($field,$res);
    }

    protected function checkLogin(){
        $url = MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME;
       // dump($_SESSION);
        $menu_id = M('menus')->getFieldByurl($url,'menu_id');
       // echo $arrRole;exit;
        if(in_array($menu_id,session('role'))==false){
            $this->error('你没有权限',U('Menus/index'));
        }
    }


    private function showMenus(){
        $menus = M('menus')
            ->where([
                'lock'=>1,
              'menu_id'=>['in',session('role')]
            ])
            ->order(['mgroup'=>'asc','msort'=>'asc'])
            ->select();
        //dump($menus);
        $this->assign('locks',$menus);
    }


}
